﻿using System;
using System.Collections.Generic;

namespace StockLib.Indicator
{
    public partial class StockBBIIndicator : StockIndicator
    {
        private List<int> maDays = new List<int>();

        public StockBBIIndicator()
            : base()
        {
            cacheCount = 1;
        }

        public override void SetDefaultParameters()
        {
            maDays.Clear();
            maDays.Add(3);
            maDays.Add(6);
            maDays.Add(12);
            maDays.Add(24);
        }

        protected override float[] CalcOutput(int index)
        {
            float[] values = new float[1];

            if (!cacheValues[0].ContainsKey(index))
            {
                float indicatorValue = 0;
                for (int i = 0; i < maDays.Count; i++)
                {
                    indicatorValue += CalcCloseMa(index, maDays[i]);
                }
                indicatorValue = indicatorValue / maDays.Count;
                cacheValues[0].Add(index, indicatorValue);
            }
            values[0] = cacheValues[0][index];

            return values;
        }
    }
}
